#define _CRT_SECURE_NO_WARNINGS
#include "sort.h"
#include "Stack.h"

void SInsertSorttest()
{
	int arr[] = { 48,62,35,77,55,14,35,98 };
	SInsertSort(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void ShellSorttest()
{
	int arr[] = { 9,1,2,5,7,4,8,6,3,5 };
	ShellSort(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void HeapSorttest()
{
	int arr[] = { 9,1,2,5,7,4,8,6,3,5 };
	//int arr[] = { 1,1,1,1,1,1,1,1,1,1 };
	HeapSort(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void SelectSorttest()
{
	//int arr[] = { 34,56,25,65,86,99,72,66 };
	int arr[] = { 9,1,2,5,7,4,8,6,3,5 };
	SelectSort(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void BubbleSorttest()
{
	int arr[] = { 9,1,2,5,7,4,8,6,3,5 };
	BubbleSort(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void QuickSorttest()
{
	int arr[] = { 9,1,2,5,7,4,8,6,3,5,-7,23,45,67,88,-21 };
	QuickSort(arr, 0, sizeof(arr) / sizeof(arr[0]) - 1);
	//QuickSortNonR(arr, 0, sizeof(arr) / sizeof(arr[0]) - 1);
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void MergerSorttest()
{
	//int arr[] = { 9,1,2,5,7,4,8,6,3,5 };
	int arr[] = { 10,6,7,1,3,9,4,2,5 ,11,-1};
	//MergerSort(arr, sizeof(arr) / sizeof(arr[0]));
	MergerSortNonR(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void CountSorttest()
{
	//int arr[] = { 10,6,7,1,3,9,4,2,5 ,11, };
	int arr[] = { -5, 4, 3, -3, -5, -3, -3, 2, 3, 4, 3, 2 };
	CountSort(arr, sizeof(arr) / sizeof(arr[0]));
	PrintArr(arr, sizeof(arr) / sizeof(arr[0]));
}

void TestOP()
{
	srand((unsigned int)time(0));
	const int N = 10000000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	if (a1 == NULL)
		exit(-1);
	int* a2 = (int*)malloc(sizeof(int) * N);
	if (a2 == NULL)
		exit(-1);
	int* a3 = (int*)malloc(sizeof(int) * N);
	if (a3 == NULL)
		exit(-1);
	int* a4 = (int*)malloc(sizeof(int) * N);
	if (a4 == NULL)
		exit(-1);
	int* a5 = (int*)malloc(sizeof(int) * N);
	if (a5 == NULL)
		exit(-1);
	int* a6 = (int*)malloc(sizeof(int) * N);
	if (a6 == NULL)
		exit(-1);
	int* a7 = (int*)malloc(sizeof(int) * N);
	if (a7 == NULL)
		exit(-1);

	for (int i = 0; i < N; ++i)
	{
		a1[i] = rand();
		//a1[i] = rand() + i;
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
	}

	int begin1 = clock();
	//SInsertSort(a1, N);
	int end1 = clock();

	int begin2 = clock();
	ShellSort(a2, N);
	int end2 = clock();

	int begin3 = clock();
	//SelectSort(a3, N);
	int end3 = clock();

	int begin4 = clock();
	HeapSort(a4, N);
	int end4 = clock();

	int begin5 = clock();
	QuickSort(a5, 0, N - 1);
	int end5 = clock();

	int begin6 = clock();
	MergerSort(a6, N);
	int end6 = clock();

	int begin7 = clock();
	//BubbleSort(a7, N);
	int end7 = clock();

	printf("SInsertSort:%d\n", end1 - begin1);
	printf("ShellSort:%d\n", end2 - begin2);
	printf("SelectSort:%d\n", end3 - begin3);
	printf("HeapSort:%d\n", end4 - begin4);
	printf("BubbleSort:%d\n", end7 - begin7);
	printf("QuickSort:%d\n", end5 - begin5);
	printf("MergerSort:%d\n", end6 - begin6);

	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
}


int main()
{
	//SInsertSorttest();
	//ShellSorttest();
	//HeapSorttest();
	//SelectSorttest();
	//BubbleSorttest();
	QuickSorttest();
	//MergerSorttest();
	//CountSorttest();
	//TestOP();
	return 0;
}